import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class RecommendationTask {

    private final RecommendationService recommendationService;

    public RecommendationTask(RecommendationService recommendationService) {
        this.recommendationService = recommendationService;
    }

    @Scheduled(cron = "0 0 2 * * ?") // 每天凌晨2点执行任务
    public void generateRecommendationsTask() {
        // 获取所有用户ID列表
        List<Integer> userIds = userService.getAllUserIds();

        // 遍历用户列表，生成并保存推荐数据
        for (Integer userId : userIds) {
            recommendationService.generateAndSaveRecommendations(userId);
        }
    }
}
